﻿using System;
using HSystem.Data;
using HSystem.Data.Core.Enum;
using HSystem.Data.Core.Factories;
using HSystem.Data.Core.Interfaces;

namespace DBCodeBuilder.Core.Classes
{
    public class DbProvider
    {
        public static void Init(string username, string password, string conStr)
        {
            string createdCS;
            try
            {
                createdCS = String.Format(conStr, username, password);
            }
            catch
            {
                throw new Exception("Connaction string is not in the correct format.");
            }
            IDataManagerSetup dataManager = DataManagerFactory.LoadConfigCustomClass("prod");
            dataManager.AddConnector(DatabaseType.Oracle, "1", createdCS, "");
            dataManager.AddService("app", "NHI", "**");
            dataManager.AddLink("app", "1", "prod");
            dataManager.GetDataManager();
        }

        public static bool TestConnection()
        {
            try
            {
                DbCustom.ExecuteNonQuery("SELECT 1 FROM DUAL", "app");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}